<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
	String isShow = request.getParameter("isShow") == null ? "" : request.getParameter("isShow");
	String id = request.getParameter("id") == null ? "" : request.getParameter("id");	
	String xm_id = request.getParameter("xm_id") == null ? "" : request.getParameter("xm_id");	
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
	
    boolean isAdd = "".equals(id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }

%>
<html>
	<head>
		<title><%=isAdd?"新建项目供货商收票单":"编辑项目供货商收票单" %></title>
		<link href="<%=contextPath%>/public/css/smart_wizard_vertical.css" rel="stylesheet"	type="text/css">
		<script type="text/javascript" src="<%=contextPath%>/public/js/jquery.smartWizard.js"></script>
		<link  rel="stylesheet"  href  ="<%=contextPath%>/public/swfupload/css/swfupload.css">
	
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
		  <script  type="text/javascript"  src="<%=contextPath%>/core/js/datastructs.js"  ></script>
			<script  type="text/javascript"  src="<%=contextPath%>/core/js/sys.js"  ></script>
			<script  type="text/javascript"  src="<%=contextPath%>/core/js/prototype.js"  ></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/attachMenu.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/Menu.js"></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/fileprogress.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/handlers.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.queue.js"  ></script>
   		 
		<script type="text/javascript">
		var flag="<%=flag%>";
		var isShow="<%=isShow%>";
		jQuery(document).ready(function() {
			if(flag == '1'){
				jQuery('#lv').form({
					onLoadSuccess:function(){
						queueCompleteOver();
					}
				});
					
			
			}else{
				jQuery("#operation_time").datetimebox('setValue',getTodaySecond());
			}
				jQuery("#rec_to_id").combogrid({
					title:'选择供货商',
					panelWidth:550,
					panelHeight:400,
					url:'<%=contextPath%>/springMVC/xmFinance/listXMSuppliers<%=isAdd ? "" : "?xm_id=" + xm_id%>',
					idField:"id",
					textField:"company",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{field:'company',title:'供应商',width:100,align:'center'},
						{field:'tel',title:'电话',width:100,align:'center'}
					]],
					toolbar:'#tb',
					onChange:function(){
						var row = jQuery('#rec_to_id').combogrid("grid").datagrid('getSelected');
						jQuery('#rec_to_name').val(row.company);
					}
				});
			<%=isAdd?"":"jQuery('#lv').form('load','"+contextPath+"/springMVC/xmFinance/getXmRecInvoiceById?id="+id+"');"%>
			          var settings = {
				      flash_url : "<%=contextPath%>/public/swfupload/swfupload.swf",
				      upload_url: "<%=contextPath%>/springMVC/fileUpload/fileupload",
				      post_params: {
				    	 "module" : "<%=com.beaut.project.util.StaticData.XM_MODULE%>"
				      },
				      file_size_limit : "100 MB",
				      file_types : "*.*",
				      file_types_description : "All Files",
				      file_upload_limit : 100,
				      file_queue_limit : 0,
				      custom_settings : {
				        uploadArea : "fsUploadArea",
				        progressTarget : "fsUploadProgress",
				        startButtonId : "btnStart",
				        cancelButtonId : "btnCancel"
				      },
				      debug: false,
				      button_image_url: "<%=contextPath%>/public/swfupload/img/uploadx4.gif",
				      button_width: "65",
				      button_height: "29",
				      button_placeholder_id: "spanButtonUpload",
				      button_text: '<span class=\"textUpload\">上传附件</span>',
				      button_text_style: ".textUpload{color:#0000ff;}",
				      button_text_top_padding : 1,
				      button_text_left_padding : 18,
				      button_width: 80,
				      button_height: 20,
				      button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
				      button_cursor: SWFUpload.CURSOR.HAND,
				      
				      file_queued_handler : fileQueued,
				      file_queue_error_handler : fileQueueError,
				      file_dialog_complete_handler : fileDialogComplete,
				      upload_start_handler : uploadStart,
				      upload_progress_handler : uploadProgress,
				      upload_error_handler : uploadError,
				      upload_success_handler : uploadSuccessOver,
				      upload_complete_handler : uploadComplete,
				      queue_complete_handler : queueCompleteOver
				    };
				    swfupload = new SWFUpload(settings);
				  
				});
			
		 function uploadSuccessOver(file, serverData){
				  try {
				    var progress = new FileProgress(file, this.customSettings.progressTarget);
				    progress.toggleCancel(false);
				    var json = null;
				    json = serverData.evalJSON();
				    if(json.rtState=="1") {
				       progress.setError();
				       progress.setStatus("上传失败");
				    } else {
				       if($('attachmentId').value!=null && $('attachmentId').value!=""){
				    	 $('attachmentId').value += ',' + json.rtData.attachmentId;
				       } 
				       else{
				    	   $('attachmentId').value = json.rtData.attachmentId;
				       }
				       if($('attachmentName').value!=null && $('attachmentName').value!=""){
				    	 $('attachmentName').value += '*' + json.rtData.attachmentName;
				       } 
				       else{
				    	   $('attachmentName').value = json.rtData.attachmentName;
				       }
				    }
				  } catch (ex) {
				    this.debug(ex);
				  }
		}
		function queueCompleteOver(){
			var attachmentIds = $("attachmentId").value;
		    var attachmentNames = $("attachmentName").value;
		    if(attachmentIds){
		      jQuery('#attaTr').show();
	       	  jQuery('#fsUploadArea').hide();
	       	  attachMenuUtil("showAtt",null,null,attachmentNames,attachmentIds,false,'attach');
		    }
		 }
				 
		  function deleteAttachment(attachmentId,attachmentName){
			  var attrIds = $("attachmentId").value;
		    var attrNames = $("attachmentName").value;
		     var attrIdArrays = attrIds.split(",");
			  var attrNameArrays = attrNames.split("*");
			 var idArray = new Array();
			 var nameArray = new Array();
			 
			 for(var i=0;i<attrIdArrays.length;i++){
				 if(attrIdArrays[i] != attachmentId){
					 idArray.push(attrIdArrays[i]);
					 nameArray.push(attrNameArrays[i]);
				 }
			 }
			 $("attachmentId").value = idArray.join(",");
			 $("attachmentName").value = nameArray.join("*");
			 if($("attachmentId").value == ""){
				 jQuery('#attaTr').hide();
			 }
		  }
		  
			function doSubmit(obj){
				
				jQuery("#lv").form('submit',{
					url:"<%=contextPath %>/springMVC/xmFinance/<%=isAdd ? "addXMRecInvoice" : "updateXMRecInvoice?id=" + id%>",
					queryParams:{"rec_type":"2","source":"2"},
					onSubmit:function(){
						var isValid = jQuery(this).form('validate');
						if(isValid){
							jQuery(obj).hide();
						}
						return isValid;
					},
					success:function(rtJson){
						rtJson = eval('(' + rtJson + ')'); 
						if (rtJson.rtState == '0'){
							warningInfo(rtJson.rtMsrg);
							eval('parent.window.opener.rtCallBack();');
							parent.window.close();
							
						}else{
							jQuery(obj).show();
							warningInfo(rtJson.rtMsrg);
						}
					}
				});
			}

		    function choseXm(){
		    	openWindow("<%=contextPath %>/springViews/xm/choseMyXM.jsp","项目选择",1000, 800);
		    	
		    }
			function rtCallBackXmSet(xm_id,xm_code,xm_name){
				  jQuery("#xm_id").val(xm_id);
			      jQuery("#xm_name").val(xm_name);
			      jQuery("#xm_code").val(xm_code);
			      
			      jQuery("#rec_to_id").combogrid("grid").datagrid("load",{
			    	  xm_id:xm_id
						
					});
			}
		     
		</script>
	</head>
	<body >
							<form id="lv"  method="post">
						<div style="width:90%;padding-left:50px;margin-top:20px" align="center">
							<table  style="border-collapse: collapse;" border="1px" width="100%" bordercolor="#0eb83a" >
							<tr>
								<td align="right" class="td1" nowrap>项目编号：</td>
								<td class="td2" nowrap>
									<input type="hidden" id="xm_id" name="xm_id" >
									<input  id="xm_code" name="xm_code" readonly="readonly" class="easyui-validatebox" data-options="required:true" onclick="choseXm();">
									<a href="javascript:void(0)" class="easyui-linkbutton"  data-options="iconCls:'icon-add',plain:false" onclick="choseXm();"></a>								</td>
								<td align="right" class="td1" nowrap>项目名称：</td>
								<td class="td2" nowrap>
									<input  id="xm_name" name="xm_name" readonly="readonly" class="easyui-validatebox" data-options="required:true" >
								</td>
							</tr>
							<tr>
								
								<td align="right" class="td1" nowrap>经办人：</td>
								<td class="td2" nowrap >
									<input type="hidden"  id="creator_id" class="easyui-validatebox" data-options="required:true" name="creator_id"  value="<%=person_id%>"/>
									<input  id="creator" name="creator" readOnly value="<%=person%>"/>
								</td>
								<td align="right"  nowrap class="td1">
										收票日期：
									</td>
									<td class="td2" nowrap >
										<input id="operation_time" name="operation_time" class="easyui-datetimebox" data-options="required:true"/>
									</td>
							</tr>
							<tr>
								
								<td align="right" class="td1" nowrap>票号：</td>
								<td class="td2" nowrap colspan="3">
									<input  id="ticket" name="ticket" style="width:99%;"  class="easyui-validatebox"  data-options="required:true" />
								</td>
							</tr>
							<tr>
							<td align="right" class="td1" nowrap>供货商：</td>
						<td class="td2" nowrap >
										<input type="text" id="rec_to_id" name="rec_to_id"  data-options="required:true"/>
										<input type="hidden" id="rec_to_name" name="rec_to_name"  />
									</td>							</td>
								<td align="right" class="td1" nowrap>收票金额：</td>
								<td class="td2" nowrap>
									<input  id="rec_value" name="rec_value" class="easyui-numberbox"  data-options="min:0,precision:2,required:true" value="0"/>
								</td>
							</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										备注描述:
									</td>
									<td class="td2" nowrap colspan="3" >
							           <textarea id="remark" name="remark"  style="height:100%;width:100%" rows="6"></textarea>

									</td>
								</tr>
									<tr id="attaTr" style="display:none">
								      <td nowrap align="right" class="td1">附件明细: </td>
								      <td class="td2"  colspan="3" >
								        <input type="hidden" id="attachmentId" name="attachmentId">
								        <input type="hidden" id="attachmentName" name="attachmentName">
								        <span id="showAtt">
								        </span>
								      </td>
							   	    </tr>
								<tr>
							      <td nowrap align="right" class="td1">附件：</td>
							      <td class="td2"  colspan="3" >
							        	 <div id="fsUploadArea" class="flash" style="width:380px;">
										     <div id="fsUploadProgress"></div>
										     <div>
										       <input type="button" id="btnStart" class="SmallButtonW" value="开始上传" onclick="swfupload.startUpload();" disabled="disabled">&nbsp;&nbsp;
										       <input type="button" id="btnCancel" class="SmallButtonW" value="全部取消" onclick="javascript:swfupload.cancelQueue();jQuery('#fsUploadArea').hide();" disabled="disabled">&nbsp;&nbsp;
										    </div>
									      </div>
									      
										    <div id="attachment1">
									          <span id="spanButtonUpload" title="上传附件"></span>
									        </div>
							      </td>
					   		   </tr>
					   		   <tr>
								<td align="right" nowrap class="td1">
								</td>
								<td  nowrap  colspan="3" >
								<%if(!"1".equals(isShow)){%>
									<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="doSubmit(this);">保存</a>
								<%} %>
									<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:parent.window.close();">关闭</a>
								</td>
							</tr>
				 			</table>
				 			</div>
				 			</form>
				 		
				 			
	</body>
</html>


